﻿using System;
using Bingosoft.Modules.DataDictionary;
using Bingosoft.Web.Utils;
using System.Web.UI;
using System.Data;

namespace Bingosoft.WebApp.Modules.DeliveredManager
{
    public partial class DeliveredEdit : FormPage
    {
        protected string Type = "";
        protected string Id = "";//相当于ForeignD
        protected string d_ID = "";//编辑用

        private DeliveredService deliveredService = new DeliveredService();

        #region 展示用字段

        protected string m_txtMaterialsNo = "";

        protected string m_txtMaterialsName = "";

        protected string m_txtMaterialsModel = "";

        protected string m_txtPrice = "";

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
           //初始化获取Type以及入库的ID
            if (!IsPostBack)
            {
                if (Request["Type"] != null)
                {
                    Type = Request["Type"].ToString();
                }
                if (Request["ID"] != null)
                {
                    Id = Request["ID"].ToString();//MaterialsNo 新建出库单
                }
                if (Request["d_ID"] != null) 
                {
                    d_ID = Request["d_ID"].ToString(); //出库的ID 直接编辑出库明细
                }
                InitPage();
            }
        }

        /// <summary>
        /// 初始化
        /// </summary>
        private void InitPage()
        {
            DataSet ds = new DataSet();
            if (d_ID != "")//编辑
            {
                ds = deliveredService.GetEditInfo(d_ID);
                if (ds.Tables[0].Rows.Count == 1)
                {
                    string m_id = ds.Tables[0].Rows[0][0].ToString();//出库ID
                    string m_type = ds.Tables[0].Rows[0][1].ToString();//出库类型
                    this.Type = m_type;
                    this.Id = m_id;
                  //  FillInfo(m_type, m_id);
                }
            }
            else
            {
                if (Type != "" && Id != "")
                {
                    FillInfo(Type, Id);
                }
            }
        }

        private void FillInfo(string Type,string Id)
        {
            DataSet ds = new DataSet();
            ds = deliveredService.GetInfo(Type, Id);
            if (ds.Tables[0].Rows.Count == 1)
            {
                m_txtMaterialsNo = ds.Tables[0].Rows[0][0].ToString();
                m_txtMaterialsName = ds.Tables[0].Rows[0][1].ToString();
                m_txtMaterialsModel = ds.Tables[0].Rows[0][2].ToString();
                m_txtPrice = ds.Tables[0].Rows[0][3].ToString();
            }
        }

        protected void Save(object sender, EventArgs e)
        {
            this.SmartFormView1.SaveOrUpdate();
            ScriptHelper.CloseDialog(this, "true");
        }
       
    }
}